package com.dsunsoft.rtu.service.impl;

import com.dsunsoft.rtu.common.enums.DeviceTypeEnum;
import com.dsunsoft.rtu.dao.RtuDeviceMapper;
import com.dsunsoft.rtu.dao.RtuDeviceRealMapper;
import com.dsunsoft.rtu.dto.RtuDeviceRealInfoDto;
import com.dsunsoft.rtu.entity.RtuDevice;
import com.dsunsoft.rtu.entity.RtuDeviceReal;
import com.dsunsoft.rtu.query.RtuDeviceQuery;
import com.dsunsoft.rtu.service.RtuDeviceRealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class RtuDeviceRealServiceImpl implements RtuDeviceRealService {

    @Autowired
    private RtuDeviceMapper deviceMapper;
    @Autowired
    private RtuDeviceRealMapper deviceRealMapper;

    @Override
    public List<RtuDeviceRealInfoDto> getList(RtuDeviceQuery query) {
        List<RtuDeviceRealInfoDto> list = new ArrayList<>();
        // 排除没有设备类型的数据
        query.setDeviceTypeList(DeviceTypeEnum.getHasDataTypeList());
        List<RtuDevice> deviceList = deviceMapper.selectList(query);
        for (RtuDevice item : deviceList) {
            // 获取降雨和水位实时数据
            List<RtuDeviceReal> realList = deviceRealMapper.selectByDeviceId(item.getDeviceId());
            list.add(new RtuDeviceRealInfoDto(item, realList));
        }
        return list;
    }
}
